import { mergeConfig, loadEnv } from 'vite';
import eslint from 'vite-plugin-eslint';
import baseConfig from './vite.config.base';

export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd()); // 读取 .env.development 等环境变量
  console.log(env)
  return mergeConfig(
    {
      mode: 'development',
      server: {
        host: '0.0.0.0',
        port: 3000,
        open: true,
        fs: {
          strict: true,
        },
        proxy: {
          '/api': {
            target: env.VITE_API_BASE_URL, // ✅ 从环境变量中读取
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''),
          },
        },
      },
      plugins: [
        eslint({
          cache: false,
          include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.vue'],
          exclude: ['node_modules'],
        }),
      ],
    },
    baseConfig
  );
};
